added Feb 2001 SDK
[windows-sources.git] / shared source / wpf / src / host / shimimpl / activationcontext.hxx
blobfd8bb8cb1d57ecd9d23d9dd7833c14bf5c286961
1 #pragma once
3 // Wrapper for a Fusion Activation Context (ACTCTX)
4 class ActivationContext
6 ActivationContext(const ActivationContext&);
7 void operator =(const ActivationContext&);
8 public:
9 ActivationContext() :
10 m_hActCtx(INVALID_HANDLE_VALUE),
11 m_actCtxCookie(0),
12 m_fAutoDeactivate(true)
16 ~ActivationContext()
18 if(m_hActCtx != INVALID_HANDLE_VALUE)
20 // If we don't deactivate the context, we can't release it either.
21 if(m_fAutoDeactivate)
23 DeActivate();
24 ReleaseActCtx(m_hActCtx);
29 bool Create(LPCWSTR manifestModulePath)
31 if (m_hActCtx != INVALID_HANDLE_VALUE || !manifestModulePath || !*manifestModulePath)
33 ASSERT(false);
34 return false;
37 ACTCTXW actctx = { sizeof(actctx) };
38 actctx.lpSource = manifestModulePath;
39 actctx.lpResourceName = MAKEINTRESOURCEW(2);
40 actctx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID;
42 m_hActCtx = CreateActCtxW(&actctx);
43 return m_hActCtx != INVALID_HANDLE_VALUE;
46 bool Activate(bool autoDeactivate = true)
48 if(m_hActCtx == INVALID_HANDLE_VALUE)
50 ASSERT(false);
51 return false;
53 m_fAutoDeactivate = autoDeactivate;
54 return ActivateActCtx(m_hActCtx, &m_actCtxCookie) != false;
57 bool DeActivate()
59 if(m_hActCtx == INVALID_HANDLE_VALUE || m_actCtxCookie == 0)
61 ASSERT(false);
62 return false;
64 ULONG_PTR cookie = m_actCtxCookie;
65 m_actCtxCookie = 0;
66 return DeactivateActCtx( 0, cookie) != false;
69 private:
70 HANDLE m_hActCtx;
71 ULONG_PTR m_actCtxCookie;
72 bool m_fAutoDeactivate;